import { Router } from 'express';
import {
  getAllUsers,
  getUserById,
  createUser,
  updateUser,
  deleteUser
} from '../controllers/userController';
import { requireAdmin, requirePermission } from '../middleware/roleAuth';

const router = Router();

// GET /api/users - 获取所有用户 (需要管理员权限)
router.get('/', requireAdmin, getAllUsers);

// GET /api/users/:id - 根据ID获取用户
router.get('/:id', getUserById);

// POST /api/users - 创建新用户 (需要管理员权限)
router.post('/', requireAdmin, createUser);

// PUT /api/users/:id - 更新用户 (需要用户更新权限)
router.put('/:id', requirePermission('user:update'), updateUser);

// DELETE /api/users/:id - 删除用户 (需要管理员权限)
router.delete('/:id', requireAdmin, deleteUser);

export default router;
